package org.wheres2.location.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class PositionView extends View {
	
	
	private Paint paint;
 	private int positionViewW;
	private int positionViewH;
	private int x = -1;
	private int y = -1;
	private int gradi = 0;
	private int color = Color.BLACK;

	public PositionView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		paint = new Paint();
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		 
		positionViewH = this.getHeight();
		positionViewW = this.getWidth();
		canvas.rotate(gradi,positionViewW/2,positionViewH/2);
		
		paint.setColor(color);
		paint.setAntiAlias(true);
	
		canvas.drawCircle(x, y, 3, paint);

	}
	
	
	public void coordinate(double distance){

		if(distance> 1000)
			   color = Color.RED;
			  else if(distance >500 && distance<=1000)
			   color = Color.BLUE;
			  else
			   color = Color.GREEN;
		
		while(distance > ((positionViewH/2)*0.56)){
			distance = distance/2;
		}
		x = (int)(positionViewW/2);
		y = (int)(positionViewH/2 - distance);
	}
	
	public void setGradi(int gradi) {
		this.gradi = gradi;
	}
	
	
}
